package com.cmwa.scbp.base.interceptor;

import java.util.Arrays;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.stereotype.Component;
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;

/**
 * 错误页面拦截器
 * @author ex-hejm
 * @date 2019年3月13日下午1:36:48
 */
@Component
public class ErrorPageInterceptor extends HandlerInterceptorAdapter {
	
	private List<Integer> errorCodeList = Arrays.asList(404, 403, 500, 501);

	@Override
	public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler)
			throws Exception {
		if (errorCodeList.contains(response.getStatus())) {
			response.sendRedirect(request.getServletContext().getContextPath() + "/index/error/" + response.getStatus() + ".do");
			return false;
		}
		return super.preHandle(request, response, handler);
	}
}